summaryrefslogtreecommitdiff
path: root/frontend/app/drive/[...path]/page.tsx
blob: bfb65ad728421c9db853779b9629a50a158f2cf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { DriveDirectoryView } from "@/components/drive/DriveDirectoryView"
import { Drive_ls } from "@/lib/drive_server"

async function fetchStorageData() {
  try {
    const response = await fetch(`${process.env.NODE_ENV === 'development' ? 'http://127.0.0.1:3000' : ''}/api/storage`, { 
      cache: 'no-store' 
    })
    if (!response.ok) {
      throw new Error('Failed to fetch storage data')
    }
    return await response.json()
  } catch (error) {
    console.error('Failed to fetch storage data:', error)
    // Return zeros on error as requested
    return {
      activeDriveUsage: 0,
      totalDiskCapacity: 0,
      totalDiskUsed: 0,
      availableDisk: 0
    }
  }
}

export default async function DriveDirectoryPage({
  params,
}: {
  params: Promise<{ path: string[] }>
}) {
  const { path: pathSegments } = await params
  // URL decode each path segment to handle special characters
  const decodedSegments = pathSegments?.map(segment => decodeURIComponent(segment)) || []
  const currentPath = '/' + decodedSegments.join('/')
  
  const [files, storageData] = await Promise.all([
    Drive_ls(currentPath, false),
    fetchStorageData()
  ])
  
  return <DriveDirectoryView path={currentPath} files={files} storageData={storageData} />
}